package cloud.tianai.ram.policy.server.condition.impl.handler;

import cloud.tianai.ram.policy.common.model.dto.Action;
import cloud.tianai.ram.policy.common.handler.AbstractConditionHandler;
import cloud.tianai.ram.policy.common.model.dto.Condition;
import cloud.tianai.ram.policy.common.handler.ConditionHandlerManager;
import cloud.tianai.ram.policy.common.model.dto.TypeDefinition;

/**
 * @Author: 天爱有情
 * @date 2022/4/1 14:31
 * @Description 条件组合器 异或
 */
public class XorConditionHandler extends AbstractConditionHandler {

    public XorConditionHandler() {
        addTypeDefinition(new TypeDefinition("xor", "异或组合器"));
    }

    @Override
    public boolean match(Condition condition, ConditionHandlerManager conditionHandlerManager, Action action) {
        for (Condition child : condition.getChildren()) {
            if (!conditionHandlerManager.match(child, action).isAllow()) {
                return true;
            }
        }
        return false;
    }
}
